package com.example.questionnaire.service.impl;

import com.example.questionnaire.dao.AgreementMapper;
import com.example.questionnaire.pojo.DO.Agreement;
import com.example.questionnaire.service.QuestionnaireAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class QuestionnaireAgreementServiceImpl implements QuestionnaireAgreementService {

    @Autowired
    private AgreementMapper agreementMapper;

    @Override
    public Agreement getAgreement(String formid) {
        if(agreementMapper.selectAllByFormid(formid) != null ){
            Agreement agreement1 = agreementMapper.selectAllByFormid(formid);
            agreement1.setId(null);
            agreement1.setCreateTime(null);
            agreement1.setModifiedTime(null);
            return agreement1;
        }
        return null;

    }

    @Override
    public boolean agreement(String formid, String title, String content, int showNum, String agree, String disagree, boolean shortestReadingTime, boolean isDisagree,int seconds) {
        agreementMapper.deleteAll(formid);
        if (agreementMapper.insert(new Agreement(formid, title, content, showNum, agree, disagree, shortestReadingTime ? 1 : 0, isDisagree ? 1 : 0,seconds)) < 1) {
            throw new RuntimeException("插入失败");
        }

        return true;
    }
}
